package com.xysq.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.xysq.util.PropertiesUtil;
import com.rockcent.model.CouponBO;
import com.xysq.lemon.R;
import com.xysq.util.UseUtil;

/**
 * Created by Steward_Han on 2015/8/14.
 */
public class CouponAdapterForCouponBO extends BaseDataAdapter<CouponBO> {
    private ViewHolder viewHolder;

    public CouponAdapterForCouponBO(Context context) {
        super(context);
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        viewHolder = new ViewHolder();
        if (null == convertView) {
            LayoutInflater mInflater = LayoutInflater.from(context);
            convertView = mInflater.inflate(R.layout.item_coupon, null);
            int screenWidth = UseUtil.getScreenWidth((Activity) context);
            int screenHeight = UseUtil.getScreenHeight((Activity) context);
            viewHolder.picImg = (ImageView) convertView.findViewById(R.id.img_pic);
            viewHolder.picImg.setMinimumHeight(screenWidth / 5 * 3);
            viewHolder.priceTxt = (TextView) convertView.findViewById(R.id.txt_price);
            viewHolder.nameTxt = (TextView) convertView.findViewById(R.id.txt_title);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        final CouponBO couponBO = itemList.get(position);
        if (null != couponBO) {
            viewHolder.picImg.setTag(couponBO.getLogoUrl());
            viewHolder.priceTxt.setText("￥" + UseUtil.handlePrice(couponBO.getEstimateAmount()));
            imageLoader.displayImage(PropertiesUtil.getImageServer() + couponBO.getLogoUrl(), viewHolder.picImg);
//            Log.e("imgUrl++++", PropertiesUtil.getImageServer() + couponModel.getLogoUrl());
            viewHolder.nameTxt.setText(String.valueOf(couponBO.getName()));
        }
        return convertView;
    }

    private static class ViewHolder {
        ImageView picImg;
        TextView nameTxt;
        TextView priceTxt;
    }

}
